package com.bw.zzy.partal2.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.bw.zzy.partal2.common.CommonResult;
import com.bw.zzy.partal2.controller.form.SelectScheduleByWorkPlanIdForm;
import com.bw.zzy.partal2.controller.form.UpdateDoctorScheduleForm;
import com.bw.zzy.partal2.controller.form.selectScheduleByDeptSubForm;
import com.bw.zzy.partal2.service.DoctorWorkPlanScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/doctor/work_plan/schedule")
@Tag(name = "DoctorWorkPlanScheduleController", description = "出诊管理接口")
@CrossOrigin(origins = "http://localhost:4000", allowCredentials = "true")
public class DoctorWorkPlanScheduleController {


    @Autowired
    private DoctorWorkPlanScheduleService doctorWorkPlanScheduleService;

    @Operation(summary = "通过诊室ID查询医生出诊计划")
    @PostMapping("/selectScheduleByDeptSub")
    @SaCheckPermission(value = {"ROOT", "SCHEDULE:SELECT"}, mode = SaMode.OR)

    public CommonResult selectScheduleByDeptSub(@RequestBody @Valid selectScheduleByDeptSubForm form) {
        Map param = BeanUtil.beanToMap(form);

        ArrayList list = doctorWorkPlanScheduleService.selectScheduleByDeptSub(param);

        return CommonResult.ok().put("result", list);
    }

    @Operation(summary = "通过WorkPlanId查询医生出诊计划")
    @PostMapping("/selectScheduleByWorkPlanId")
    @SaCheckPermission(value = {"ROOT", "SCHEDULE:UPDATE"}, mode = SaMode.OR)
    public CommonResult selectScheduleByWorkPlanId(@RequestBody @Valid SelectScheduleByWorkPlanIdForm form) {
        HashMap map = doctorWorkPlanScheduleService.selectScheduleByWorkPlanId(form.getWorkPlanId());

        return CommonResult.ok().put("result", map);
    }

    @Operation(summary = "更新医生出诊计划")
    @PostMapping("/updateSchedule")
    @SaCheckPermission(value = {"ROOT", "SCHEDULE:UPDATE"}, mode = SaMode.OR)
    public CommonResult updateSchedule(@RequestBody @Valid UpdateDoctorScheduleForm form) {
        Map param = BeanUtil.beanToMap(form);
        doctorWorkPlanScheduleService.updateSchedule(param);
        return CommonResult.ok();
    }

}
